
import React, {Component } from "react";
import Qs from 'qs'
import axios from "../../../../http";
import {List,SearchBar, NavBar} from "antd-mobile";
import {withRouter} from "react-router";
import {PRIVATE_ROUTE} from "../../../../route.constants";
import Item from "antd-mobile/es/components/dropdown/item";
class UserSchedule extends React.Component {

    constructor(props) {

        super(props);

        this.state={userList:[],hasMore:true,searchBarValue:'',};

    }
    loadUserData=(likeName)=>{
        axios.post('api/core/access/user/findAllExceptLoginUser', Qs.stringify({
            likeName:likeName
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  dataList=response.data.data;
                this.setState({userList:dataList});
            })
            .catch(function (error) {

            });
    }
    onChange=(val)=>{
        console.log(val)
        
        this.props.history.push({ pathname: "/main/"+PRIVATE_ROUTE.APP_OA_WORK_SCHEDULE_USER_DETAIL, state: val });
    }

    searchBarOnChange=(val: string)=>{
        this.setState({searchBarValue:val});
        this.loadUserData(val);
    }
    componentDidMount() {
        if(this.props.location.state!=undefined){
            this.setState(this.props.location.state);
        }
        this.loadUserData('')
    }

    goBack=()=>{
        
            this.props.history.push({ pathname: "/"})
    }

    render(){
        return(
            <>
                <NavBar onBack={this.goBack}>请选择用户</NavBar>
                <SearchBar  placeholder="输入姓名搜索" onChange={this.searchBarOnChange}/>
                <List title='可点击列表'   >
                    {this.state.userList.map((item, index) => (
                        //  <CheckList.Item value={item.realName+'_'+item.id}>{item.name+'('+item.realName+')'}</CheckList.Item>
                        <List.Item  key={item.id} onClick={e=>this.onChange({realName:item.realName,id:item.id})}>{item.name+'('+item.realName+')'}</List.Item>
                    ))}
                </List>
            </>
        )
    }
}

export default withRouter(UserSchedule)